import { ref, computed } from 'vue'
import { defineStore } from 'pinia'

export const useCounterStore = defineStore('counter', () => {
    let counter=ref([])
    function all(data,goods_id){
      let username=localStorage.getItem('username')
      let wch=counter.value.find(item=>item.goods.goods_id==goods_id)
      if(wch){
        wch.number++
      }
      else{
        counter.value.push({
          username:username,
          goods:data,
          id:Math.floor(Math.random()*1000000),
          Number:1,
          checked:false

        })
      }
    }

  return {counter,all  }
},
  {
    persist: true,
  },
)
